package client

import (
	"github.com/douyu/jupiter/pkg/xlog"
	"k8s.io/apimachinery/pkg/util/wait"
	"k8s.io/client-go/informers"
	"k8s.io/client-go/kubernetes"
	"k8s.io/client-go/tools/clientcmd"
)

var KubeManger  = NewKubeManger()

type kubeManger struct {
	ClientSet *kubernetes.Clientset
}

func NewKubeManger() *kubeManger {
	return &kubeManger{}
}

// 初始化我们的k8s client
func (this *kubeManger) InitClient() {

	clientConfig, err := clientcmd.BuildConfigFromFlags("", "/Users/local/go/src/kubeManger/config/k8sconfig.yaml")
	if err != nil {
		xlog.Errorf("%s %s  cmd.NewClientConfigFromBytes err %s")
		return
	}

	this.ClientSet, err = kubernetes.NewForConfig(clientConfig)
	if err != nil {
		xlog.Errorf("%s %s kubernetes.NewForConfig err %s")
		return
	}
}



// 初始化我们的k8s inform
func (this *kubeManger) InitInformer()  {
	 deployController:=  &DeployHandler{}
	factory := informers.NewSharedInformerFactory(this.ClientSet, 0)
	factory.Apps().V1().Deployments().Informer().AddEventHandler(deployController)
	factory.Start(wait.NeverStop)
}